<?php
    require_once "weixin_info.php";
    require_once "config.php";
    $id = $_GET['id'];
    $order_sql = $mysql->query("select * from dyspw_goods_order where id=".$id);//è§†é¢‘
    $order = $order_sql->fetch_all(MYSQLI_ASSOC);

    require_once "shipping.php";
    $Shipping = new Shipping();
    $match_info = $Shipping->GetMaiYaTianData('/order/detail/',array('order_id'=>$order[0]['match_id']));//配送平台返回的订单详情
    // print_r($match_info);exit;
    // $match_info['data']['order_status'] = 40;
    // print_r($match_info);exit;
    if($match_info['data']['order_status'] == 50 ){
        $mysql->query("UPDATE dyspw_goods_order SET  state = 5 where id=".$order[0]['id']);
    }elseif ($match_info['data']['order_status'] == 60) {
        $mysql->query("UPDATE dyspw_goods_order SET  state = 6 where id=".$order[0]['id']);
    }
    $shop_sql = $mysql->query("select * from dyspw_member where id=".$order[0]['shop_id']);//è§†é¢‘
    $shop = $shop_sql->fetch_all(MYSQLI_ASSOC);
    $address_sql = $mysql->query("select * from dyspw_mem_address where id=".$order[0]['add_id']);//è§†é¢‘
    $address = $address_sql->fetch_all(MYSQLI_ASSOC);
    $goods_sql = $mysql->query("select * from dyspw_goods where id=".$order[0]['goods_id']);//è§†é¢‘
    $goods = $goods_sql->fetch_all(MYSQLI_ASSOC);
    $waimai_sql = $mysql->query("select * from dyspw_shop_waimai where id=".$order[0]['waimai_id']);//è§†é¢‘
    $waimai = $waimai_sql->fetch_all(MYSQLI_ASSOC);

 ?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>订单详情</title>
    <script src="js/mui.min.js"></script>
    <link href="css/order_detail.css" rel="stylesheet" />
    <link href="css/mui.min.css" rel="stylesheet" />
    <script src="js/layer/layer.js" type="text/javascript"></script>
    <script type="text/javascript" charset="utf-8">
        mui.init();
    </script>
    <script>
        var _hmt = _hmt || [];
        (function () {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?cb5d49b07e0a753dc8ee27ba2c73495d";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>
</head>

<body>
    <div class="container">
        <div class="top">
           <div class="header">
            <div class="header-left">
                <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
                <p>订单详情</p>
            </div>
            <div class="header-right">
                <a class="mui-icon mui-icon-refreshempty" href=""></a>
            </div>
           </div>
            <div class="mui-card">
                <?php if($order[0]['state'] == 0){ ?>
                    <div class="detail-card-header">
                        <p class="header-title">订单未支付</p>
                    </div>
                <?php }elseif($order[0]['state'] == 1){ ?>
                    <div class="detail-card-header">
                        <p class="header-title">订单已支付，等待商家接单</p>
                    </div>
                <?php }elseif($order[0]['state'] == 2){ ?>
                    <?php switch ($match_info['data']['order_status']) { case 1:?>
                        <div class="detail-card-header">
                            <p class="header-title">商家已接单</p>
                        </div>
                    <?php break;case 10: ?>
                        <div class="detail-card-header">
                            <p class="header-title">等待骑手接单</p>
                        </div>
                    <?php break;case 20: ?>
                        <div class="mui-card-header">
                            <h3>等待骑手取货中<p class="inner">由 <?php echo $match_info['data']['logistic'] ?>快递配送</p></h3>
                            <div class="imag-show">
                                <p>预计<span><?php echo date('H:i', $match_info['data']['finish_time']) ?></span>送达</p>
                                <img src="./images/rider_img.jpg" />
                            </div>
                        </div>
                        <div class="mui-card-content">
                            <a href="tel:<?php echo $match_info['data']['rider_phone'] ?>"type="button" class="mui-btn mui-btn-outlined">电话骑士</a>
                        </div>
                    <?php break;case 30: ?>
                        <div class="mui-card-header">
                            <h3>骑手已取货<p class="inner">由 <?php echo $match_info['data']['logistic'] ?>快递配送</p></h3>
                            <div class="imag-show">
                                <p>预计<span><?php echo date('H:i', $match_info['data']['finish_time']) ?></span>送达</p>
                                <img src="./images/rider_img.jpg" />
                            </div>
                        </div>
                        <div class="mui-card-content">
                            <a href="tel:<?php echo $match_info['data']['rider_phone'] ?>"type="button" class="mui-btn mui-btn-outlined">电话骑士</a>
                        </div>
                    <?php break;case 40: ?>
                        <div class="mui-card-header">
                            <h3>骑手配送中<p class="inner">由 <?php echo $match_info['data']['logistic'] ?>快递配送</p></h3>
                            <div class="imag-show">
                                <p>预计<span><?php echo date('H:i', $match_info['data']['finish_time']) ?></span>送达</p>
                                <img src="./images/rider_img.jpg" />
                            </div>
                        </div>
                        <div class="mui-card-content">
                            <a href="tel:<?php echo $match_info['data']['rider_phone'] ?>"type="button" class="mui-btn mui-btn-outlined">电话骑士</a>
                        </div>
                    <?php break;case 50: ?>
                        <div class="detail-card-header">
                            <p class="header-title">订单已完成</p>
                            <h5 class="sub-title">感谢您对5拍8外卖的信任，期待再次光临。</h5>
                            <p class="tip">订单已准时送达！</p>
                        </div>
                        <div class="mui-card-content">
                            <button type="button" class="mui-btn mui-btn-outlined">申请退款</button>
                            <button type="button" class="mui-btn mui-btn-outlined">再来一单</button>
                        </div>
                    <?php break;case 60: ?>
                        <div class="detail-card-header">
                            <p class="header-title">订单已取消</p>
                        </div>
                    <?php break;} ?>
                <?php }elseif ($order[0]['state'] == 5) { ?>
                    <div class="detail-card-header">
                        <p class="header-title">订单已完成</p>
                        <h5 class="sub-title">感谢您对5拍8外卖的信任，期待再次光临。</h5>
                        <p class="tip">订单已准时送达！</p>
                    </div>
                    <div class="mui-card-content">
                        <button type="button" class="mui-btn mui-btn-outlined">申请退款</button>
                        <button type="button" class="mui-btn mui-btn-outlined">再来一单</button>
                    </div>
                <?php }elseif ($order[0]['state'] == 6) { ?>
                    <div class="detail-card-header">
                        <p class="header-title">订单已取消</p>
                    </div>
                <?php } ?>
            </div>
            <!-- <div class="mui-card">
                页眉，放置标题
                <div class="mui-card-header second">
                    <p class="title">美食推荐</p>
                </div>
                内容区
                <div class="mui-card-content">
                    <div class="mui-slider">
                        <div class="mui-slider-group">
                            <div class="mui-slider-item">
                                <a href="#">
                                    <img src="./images/driver.png" />
                                    <p>牛家人大碗牛肉面</p>
                                    <p class="blue">4.8分</p>
                                    <p class="grey">30分钟送达</p>
                                </a>
                            </div>
                            <div class="mui-slider-item">
                                <a href="#">
                                    <img src="./images/driver.png" />
                                    <p>牛家人大碗牛肉面</p>
                                    <p class="blue">4.8分</p>
                                    <p class="grey">30分钟送达</p>
                                </a>
                            </div>
                            <div class="mui-slider-item">
                                <a href="#">
                                    <img src="./images/driver.png" />
                                    <p>牛家人大碗牛肉面</p>
                                    <p class="blue">4.8分</p>
                                    <p class="grey">30分钟送达</p>
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </div> -->
            <div class="mui-card food-card">
                <!--页眉，放置标题-->
                <div class="mui-card-header">
                    <h4>Top One <?php echo $shop[0]['username'] ?>></h4>
                    <?php if($_SESSION['Member_info'][0]['is_vip'] == 3 && $_SESSION['Member_info'][0]['id'] == $order[0]['shop_id']){ ?>
                        <?php if($order[0]['state'] == 0){ ?>
                            <button class="" type="button" name="button" order_id=<?php echo $order[0]['id']; ?>>未支付</button>
                        <?php }elseif($order[0]['state'] == 1){ ?>
                            <button class="order_meet" type="button" name="button" order_id=<?php echo $order[0]['id']; ?>>待接单</button>
                        <?php }elseif($order[0]['state'] == 2){ ?>
                            <?php switch ($match_info['data']['order_status']) { case 1:?>
                                <button class="" type="button" name="button" order_id=<?php echo $order[0]['id']; ?>>商家已接单</button>
                            <?php break;case 10: ?>
                                <button class="" type="button" name="button" order_id=<?php echo $order[0]['id']; ?>>等待骑手接单</button>
                            <?php break;case 20: ?>
                                <button class="" type="button" name="button" order_id=<?php echo $order[0]['id']; ?>>取货中</button>
                            <?php break;case 30: ?>
                                <button class="" type="button" name="button" order_id=<?php echo $order[0]['id']; ?>>已取货</button>
                            <?php break;case 40: ?>
                                <button class="" type="button" name="button" order_id=<?php echo $order[0]['id']; ?>>配送中</button>
                            <?php break;case 50: ?>
                                <button class="" type="button" name="button" order_id=<?php echo $order[0]['id']; ?>>完成</button>
                            <?php break;case 60: ?>
                                <button class="" type="button" name="button" order_id=<?php echo $order[0]['id']; ?>>已取消</button>
                            <?php break;} ?>
                        <?php }elseif ($order[0]['state'] == 5) { ?>
                            <button class="" type="button" name="button" order_id=<?php echo $order[0]['id']; ?>>已完成</button>
                        <?php }elseif ($order[0]['state'] == 6) { ?>
                            <button class="" type="button" name="button" order_id=<?php echo $order[0]['id']; ?>>已取消</button>
                        <?php } ?>
                    <?php } ?>
                </div>
                <!--内容区-->
                <div class="mui-card-content">
                    <div class="line">
                        <p></p>
                    </div>

                    <?php
                        $goods=json_decode($order[0]['order_details'],true);
                        if(($order[0]['order_type'] == 'waimai') && is_array($goods)){
                    ?>
                        <!--外卖商品信息展示-->
                        <?php foreach ($goods as $val){?>
                                <div class="flex">
                                    <div class="flex-second">
                                        <img src="<?php echo $val['img'] ?>" />
                                        <div>
                                            <p><?php echo $val['title'] ?></p>
                                            <p class="grey"><?php echo $val['details'] ?></p>
                                            <p class="grey">x<?php echo $val['num'] ?></p>
                                        </div>
                                    </div>
                                    <div>
                                        <label><span>¥</span><?php echo $val['money'] ?></label>
                                    </div>
                                </div>
                        <?php }?>
                    <?php }else{?>
                        <div class="flex">
                            <div class="flex-second">
                                <img src="<?php echo $goods[0]['img'] ?>" />
                                <div>
                                    <p><?php echo $goods[0]['title'] ?></p>
                                    <p class="grey"><?php echo $goods[0]['details'] ?></p>
                                    <p class="grey">X1</p>
                                </div>
                            </div>
                            <div>
                                <label><span>¥</span><?php echo $order[0]['Price'] ?></label>
                            </div>
                        </div>
                    <?php }?>

                    <div class="flex">
                        <p>包装费</p>
                        <label><span>¥</span><?php echo $order[0]['pack_fee'] ?></label>
                    </div>
                    <div class="flex">
                        <p>费送费</p>
                        <label><span>¥</span><?php echo $order[0]['delivery_fee'] ?></label>
                    </div>
                    <div class="line">
                        <p></p>
                    </div>
                </div>
                <!--页脚，放置补充信息或支持的操作-->
                <div class="mui-card-footer footer">
                    <p>合计&nbsp;&nbsp;<label><span>¥</span><?php echo $order[0]['Totalprice']; ?></label></p>
                </div>
            </div>
            <div class="infor mui-card">
                <p class="infor-title">配送信息</p>
                <div class="infor-content">
                    <div>
                        <label>期望时间</label>
                        <p>立即配送</p>
                    </div>
                    <div>
                        <label>配送地址</label>
                        <p style="margin-bottom: 0;"><?php echo $address[0]['add_place']; ?>
                        <br/>
                        <?php echo $address[0]['add_link']; ?>（<?php if($address[0]['add_sex'] == 2){echo '女士'; }else{echo '男士';}?>）<?php echo $address[0]['add_mobile']; ?>
                        </p>
                    </div>
                    <div>
                        <label>配送服务</label>
                        <p>骑手配送</p>
                    </div>
                    <div>
                        <label>备注：</label>
                        <p><?php echo $order[0]['remarks']; ?></p>
                    </div>
                    <div>
                        <label>餐具数量：</label>
                        <p><?php echo $order[0]['meal_num']; ?>份</p>
                    </div>
                </div>
            </div>

            <div class="infor mui-card sure">
                <p class="infor-title">订单信息</p>
                <div class="infor-content">
                    <div>
                        <label>订单号码</label>
                        <p><?php echo $order[0]['ordernum'] ?></p>
                    </div>
                    <div>
                        <label>下单时间</label>
                        <p><?php echo date('Y-m-d H:i:s', $order[0]['time']); ?></p>
                    </div>
                    <div>
                        <label>支付方式</label>
                        <p>在线支付</p>
                    </div>
                </div>
            </div>

            <?php if(($match_info['data']['order_status'] == 40) && ($_SESSION['Member_info'][0]['is_vip'] !== 3)){ ?>
                <style>
                    .sure{margin-bottom: 55px}
                </style>
                <button onclick="confirmOrder(<?php echo $order[0]['id']; ?>)" style="width: 100%;padding:10px 0;position: fixed;bottom: 0;left:0">确认收货</button>
                <script>
                    function confirmOrder(oid) {
                        $.ajax({
                            url: "/xiaochengxu/api/order.php?action=confirmOrder",
                            type: "post",
                            data: {'id':oid},
                            dataType: 'JSON',
                            success: function(ret) {
                                if(!ret.code){
                                    layer.open({content: ret.message,skin: 'msg',time: 3});
                                    window.location.reload();
                                }else{
                                    layer.open({content: ret.message,skin: 'msg',time: 3});
                                }
                            }
                        })
                    }
                </script>
            <?php }?>

        </div>
    </div>


    <!-- 模板引擎 -->
    <!-- <script type="text/html" id="tpl">
		{{ each items v i }}
		<div class="mui-card">
			<div class="mui-card-content">
				<img src="{{ v }}" alt="" class="itemImg">
			</div>
			<div class="mui-card-footer mui-row">
				<div class="title mui-ellipsis mui-col-xs-12">强化地板-白色爱琴海</div>
				<div class="desc mui-ellipsis mui-col-xs-12">欧式风格:浪漫艺术与生活品质的追求</div>
				<div class="data mui-col-xs-12">
					<div class="price">¥<span class="num">999</span>/平</div>
					<div class="salseNum">已售2份</div>
				</div>
			</div>
		</div>
		{{ /each }}
	</script> -->
    <script src="js/jquery-2.2.4.min.js"></script>
    <script src="js/jquery.waterfall.js"></script>
    <script src="js/template-web.js"></script>
    <script>
        $(function () {
            render()

            function render() {
                // var dataList = ["./images/9965de69c69b70d0dab1bb65cd5dc62e.jpg",
                // 	"./images/9965de69c69b70d0dab1bb65cd5dc62e.jpg",
                // 	"./images/9965de69c69b70d0dab1bb65cd5dc62e.jpg", "./images/9965de69c69b70d0dab1bb65cd5dc62e.jpg",
                // 	"./images/9965de69c69b70d0dab1bb65cd5dc62e.jpg", "./images/9965de69c69b70d0dab1bb65cd5dc62e.jpg",
                // 	"./images/9965de69c69b70d0dab1bb65cd5dc62e.jpg", "./images/9965de69c69b70d0dab1bb65cd5dc62e.jpg",
                // ]
                // var htmlStr = template("tpl", dataList);
                // $('.cardList').append(htmlStr);

                //当窗口大小重置之后，重新执行
                $(window).on('resize', function () {
                    $('.cardList').waterFall();
                })


                //当窗口加载完毕，执行瀑布流
                $(window).on('load', function () {
                    $('.cardList').waterFall();
                })
                // var gallery = mui('.mui-slider');
                // gallery.slider({
                // 	interval: 1000 //自动轮播周期，若为0则不自动播放，默认为0；
                // });
            }
        })
        $(function(){
            $(".order_meet").click(function(){
                var id = $(this).attr('order_id');
                $.ajax({
                    url: "order_ajax.php",
                    type: "post",
                    data: {'id':id},
                    dataType: 'JSON',
                    success: function(ret) {
                        if(ret.status == 'y'){
                            layer.open({content: ret.info,skin: 'msg',time: 3});
                            window.location.reload();
                        }else if (ret.status == 'n') {
                            layer.open({content: ret.info,skin: 'msg',time: 3});
                        }
                    }
                })
            })
        })
    </script>
</body>

</html>
